import { createSlice } from "@reduxjs/toolkit"

export const numSlice = createSlice({
    name: 'numInfo',
    initialState: {
        value: 10
    },
    reducers: {
        add: (state, {payload}) => {
            // console.log(payload);
            return ({ value: state.value + payload })

        }
    },
})

//把数据和方法分别导出

export const { add } = numSlice.actions;

// export const  asyncAdd = (payload:any)=>{

//     return  (dispatch:any)=>{

//         setTimeout(()=>{
//             dispatch(add(payload))
//         },3000)

//     }

// }

export const  asyncAdd = (payload:any)=>(dispatch:any)=>{
    
        setTimeout(()=>{
            dispatch(add(payload))
        },3000)

    
}

export default numSlice.reducer;
